package Demo3;


import java.io.PrintStream;

public class TestPerson {

    //深拷贝：拷贝类中引用指向的对象
    public static void main (String[] args) throws CloneNotSupportedException {

        //实例化对象
        Person person1 = new Person("huahua",3);


        //深拷贝
        Person person2 = (Person) person1.clone();

        person2.m.money = 20;


        System.out.println("person1:" + person1.m.money);
        System.out.println("person2:" + person2.m.money);


    }

    //浅拷贝：只能拷贝类中的引用，但引用指向的对象不可拷贝
    public static void main1(String[] args) throws CloneNotSupportedException {

        Person person1 = new Person("aa",18);
        Person person2 = (Person) person1.clone();


        //浅拷贝
        System.out.println(person1);
        System.out.println(person2);

        person2.m.money = 30;

        System.out.println(person1.m.money);
        System.out.println(person2.m.money);

    }
}
